package com.hn.controller;

import com.hn.pojo.User;
import com.hn.service.UserService;
import com.hn.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 部门管理Controller
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    //加入用户
    @PostMapping
    public Result insertUser(User user){
        userService.inserUser(user);
        return Result.success();
    }
    //删除用户
    @DeleteMapping("/{id}")
    public Result deleteUser(@PathVariable Integer id){
        userService.deleteUser(id);
        return Result.success();
    }
    //查询用户
    @GetMapping("/{id}")
    public Result selectUserById(@PathVariable Integer id){
        User user = userService.selectUserById(id);
        return Result.success(user);
    }
    @GetMapping
    public Result selectAll(){
        List<User> users=userService.list();
        return Result.success(users);
    }
}
